cmake_minimum_required(VERSION 3.5)

find_package(GTest REQUIRED)

file(GLOB SERVER_UNITTEST_SRCS ${CMAKE_CURRENT_LIST_DIR}/*.cpp)
message(STATUS "SERVER_UNITTEST_SRCS = ${SERVER_UNITTEST_SRCS}")

if(TESTING_ALL_IN_ONE)          # 编译成整包
    add_executable(test_all)
    target_sources(test_all PRIVATE ${SERVER_UNITTEST_SRCS})
    target_include_directories(${target} PRIVATE ${PROJECT_SOURCE_DIR}/app)
    target_link_directories(${target} PRIVATE ${PROJECT_BINARY_DIR}/app)
    target_link_libraries(${target} PRIVATE GTest::Main gmock SimDriverBoard_static)
    
else()                          # 每个测试文件单独编译
    foreach (filename IN LISTS SERVER_UNITTEST_SRCS)
        get_filename_component(target ${filename} NAME_WE)
        add_executable(${target} ${filename})
        target_include_directories(${target} PRIVATE ${PROJECT_SOURCE_DIR}/app)
        target_link_directories(${target} PRIVATE ${PROJECT_BINARY_DIR}/app)
        target_link_libraries(${target} PRIVATE GTest::Main gmock SimDriverBoard_static)
    endforeach ()

endif()

execute_process(COMMAND cp -rf ${CMAKE_CURRENT_LIST_DIR}/test_data ${CMAKE_CURRENT_BINARY_DIR})
